package com.game.arena;

import com.game.gateway.context.GatewayMessageConsumerService;
import com.game.gateway.context.ServerConfig;
import com.game.arena.handler.ArenaGatewayHandler;
import com.game.gateway.handler.GameChannelIdleStateHandler;
import com.game.netty.game.messagedispatcher.DispatchGameMessageService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

/**
 * @Author 林道敬
 * @Date 2023-08-24
 * @Description
 **/
@SpringBootApplication(scanBasePackages = { "com.game" })
public class ArenaApplication {
    public static void main(String[] args) {
        ApplicationContext context = SpringApplication.run(ArenaApplication.class, args);//初始化spring boot环境
        ServerConfig serverConfig = context.getBean(ServerConfig.class);//获取配置的实例
        DispatchGameMessageService.scanGameMessages(context, serverConfig.getServiceId(), "com.game");// 扫描此服务可以处理的消息
        GatewayMessageConsumerService gatewayMessageConsumerService = context.getBean(GatewayMessageConsumerService.class);//获取网关消息监听实例
        gatewayMessageConsumerService.start((gameChannel) -> {//启动网关消息监听，并初始化GameChannelHandler
            // 初始化channel
            gameChannel.getChannelPiple().addLast(new GameChannelIdleStateHandler(120, 120, 100));
            gameChannel.getChannelPiple().addLast(new ArenaGatewayHandler(context));
        },serverConfig.getServerId());
    }
}
